package com.yongbao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yongbao.model.domain.DishDO;
import com.yongbao.model.request.DishRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhanghong
 */
@Repository
public interface DishMapper extends BaseMapper<DishDO> {
    DishDO selectDOById(Long id);
    List<DishDO> selectDOList(DishDO dish);
    int insertDO(DishDO dish);
    int batchInsertDO(List<DishDO> dishDOList);
    int updateDO(DishDO dish);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from dish",
            "   <where>",
            "       deleted=0",
            "       <if test=\"param.dishName!=null and param.dishName!=''\">and dish_name like concat('%',#{param.dishName},'%')</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") DishRequest param);
    @Select({"<script>",
            "   select * from dish",
            "   <where>",
            "       deleted=0",
            "       <if test=\"param.dishName!=null and param.dishName!=''\">and dish_name like concat('%',#{param.dishName},'%')</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<DishDO> pageQuery(@Param("param") DishRequest param, @Param("limit") int limit, @Param("offset") long offset);
}
